package com.project.controller;

import com.framework.core.result.APIObjResponse;
import com.project.base.BaseController;
import com.project.biz.CmsProductBiz;
import com.project.biz.CmsShoppingCartBiz;
import com.project.common.model.UserInfo;
import com.project.pojo.dto.ProductDetailDTO;
import com.project.pojo.dto.UserShoppingCartDTO;
import com.project.pojo.model.AddShoppingCartModel;
import com.project.pojo.model.DelShoppingCartModel;
import com.project.pojo.model.UpdateShoppingCartCountModel;
import com.project.pojo.model.UpdateShoppingCartSkuModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 购物车
 * @Author: zhuchi
 * @CreateDate: 2020/10/15 22:44
 * @Version: 1.0
 */
@Api(value = "CmsShoppingCartController", description = "购物车")
@RestController
@RequestMapping("/cart")
@Slf4j
public class CmsShoppingCartController extends BaseController {

    /**
     * 购物车业务层接口类
     */
    @Autowired
    private CmsShoppingCartBiz shoppingCartBiz;

    /**
     * 添加购物车
     * @param addShoppingCartModel
     * @return
     */
    @ApiOperation(value = "添加购物车", httpMethod = "POST")
    @PostMapping(value = "/addShoppingCart")
    public APIObjResponse<Integer> addShoppingCart(@Validated @RequestBody AddShoppingCartModel addShoppingCartModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.shoppingCartBiz.addShoppingCart(addShoppingCartModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 修改购物车商品规格
     * @param updateShoppingCartSkuModel
     * @return
     */
    @ApiOperation(value = "修改购物车商品规格", httpMethod = "POST")
    @PostMapping(value = "/updateShoppingCartSku")
    public APIObjResponse<Integer> updateShoppingCartSku(@Validated @RequestBody UpdateShoppingCartSkuModel updateShoppingCartSkuModel){
        int result = this.shoppingCartBiz.updateShoppingCartSku(updateShoppingCartSkuModel);
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 修改购物车商品数量
     * @param updateShoppingCartCountModel
     * @return
     */
    @ApiOperation(value = "修改购物车商品数量", httpMethod = "POST")
    @PostMapping(value = "/updateShoppingCartCount")
    public APIObjResponse<Integer> updateShoppingCartCount(@Validated @RequestBody UpdateShoppingCartCountModel updateShoppingCartCountModel){
        int result = this.shoppingCartBiz.updateShoppingCartCount(updateShoppingCartCountModel);
        return APIObjResponse.success("操作成功", result);
    }

    /**
     * 获取购物车信息
     * @return
     */
    @ApiOperation(value = "获取购物车信息", httpMethod = "GET")
    @ApiResponses({@ApiResponse(code = 200, message = "OK", response = UserShoppingCartDTO.class)})
    @GetMapping(value = "/getUserShoppingCart")
    public APIObjResponse<UserShoppingCartDTO> getUserShoppingCart(){
        UserInfo userInfo = super.getLoginUser();
        UserShoppingCartDTO userShoppingCartDTO = this.shoppingCartBiz.getUserShoppingCart(userInfo.getBaseUserId());
        return APIObjResponse.success("查询成功", userShoppingCartDTO);
    }

    /**
     * 删除购物车商品
     * @param delShoppingCartModel
     * @return
     */
    @ApiOperation(value = "删除购物车商品", httpMethod = "POST")
    @PostMapping(value = "/delUserShoppingCart")
    public APIObjResponse<Integer> delUserShoppingCart(@Validated @RequestBody DelShoppingCartModel delShoppingCartModel){
        UserInfo userInfo = super.getLoginUser();
        int result = this.shoppingCartBiz.delUserShoppingCart(delShoppingCartModel, userInfo.getBaseUserId());
        return APIObjResponse.success("操作成功", result);
    }

}
